﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace DAMBAOCLPM
{
    public partial class frmKetquathi : Form
    {
        SqlDataAdapter da;
        public static String sql;
        public frmKetquathi()
        {
            InitializeComponent();
        }

        private void frmKetquathi_Load(object sender, EventArgs e)
        {
            clsConnection.CreateConnection();
            this.Width = clsVariables.Width_This - 21;
            this.Height = clsVariables.Height_This - clsVariables.Height_TopMenu - 65;
            this.Top = clsVariables.Height_TopMenu - 66;
            this.Left = 0;
            //Load dư liệu lên combobox đơn vị
            da = new SqlDataAdapter("select * from DONVI", clsConnection.con);
            DataTable tb = new DataTable();
            da.Fill(tb);
            cbodonvi.DataSource = tb;
            cbodonvi.DisplayMember = "TENKHOA";
            cbodonvi.ValueMember = "MAKHOA";
            cbodonvi.Text = "";

        }

        private void btthoat_Click(object sender, EventArgs e)
        {
            DialogResult = MessageBox.Show("Bạn có muốn thoát không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (DialogResult == DialogResult.OK)
            {
                Application.Exit();
            }
        }

        private void cbodonvi_SelectedIndexChanged(object sender, EventArgs e)
        {
            clsConnection.CreateConnection();
            sql = " select a.SBD, a.HOLOT, a.TEN, a.NGAYSINH, a.NOISINH, b.TENMON, c.MADE, count(c.STTCAU) as socaudung, sum(d.SODIEM) as diem from THISINH a, MON b, CHITIETBAILAM c, CHITIETDAPAN d where a.MAKHOA = '" + cbodonvi.SelectedValue.ToString() + "'and  a.SBD = c.SBD and c.MAMON = b.MAMON and c.MADE = d.MADE and c.STTCAU = d.STTCAUDETHI and c.PHUONGAN = d.PHUONGAN group by a.SBD, a.HOLOT, a.TEN, a.NGAYSINH, a.NOISINH, b.TENMON, c.MADE ";
            da = new SqlDataAdapter(sql, clsConnection.con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            da.Dispose();
            dt.Columns.Add("STT", Type.GetType("System.Int32"));
            for (int i = 0; i <= dt.Rows.Count - 1; i++)
            {
                dt.Rows[i]["STT"] = i + 1;

            }
            dtvXemdanhsach.DataSource = dt;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            frmRketquathi f = new frmRketquathi();
            f.Show();
        }

    }
}
